/**
 * Copyright(C) 2008 Matthias Braunhofer
 * All rights reserved
 *
 * Created on: 05.09.2008
 */

package it.cums.ui.actions;

import it.cums.ui.printing.PrintingDesign;
import net.sf.paperclips.PaperClips;
import net.sf.paperclips.PrintJob;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Display;

public class PrintAction extends Action {
	private Object object;
	
	public PrintAction(Object object) {
		this.object = object;
	}
	
	
	public void run() {
		PrintJob printJob = new PrintJob(object.toString(), PrintingDesign.createPrint(object));
		PrintDialog dialog = new PrintDialog(Display.getDefault().getActiveShell(), SWT.NONE);
        PrinterData printerData = dialog.open();
        if (printerData != null) {
        	PaperClips.print(printJob, printerData);
        }
	}
}
